/**
 * @function 博文管理控制器
 * @author anytao
 * @created 2016-07-02
 * @version 1.0
 */

'use strict';
import Base from './base.js';
import request from 'request';

export default class extends Base {

    /**
     * 博文列表页面
     */
    indexAction() {
            this.assign("title", "博文列表");
            return this.display();
        }
        /**
         * 新建/编辑博文视图
         */
    async editAction() {
        let articleId = this.get('articleId');
        // var that = this;
        // request('http://127.0.0.1:8360/api/article/get?articleId=' + articleId, function(error, response, body) {

        //     if (!error && response.statusCode == 200) {

        //         that.assign('article', JSON.parse(body));
        //         that.assign('title', '博文管理');
        //         return that.display();
        //     }
        // });
        
        //使用箭头函数
        request('http://127.0.0.1:8360/api/article/get?articleId=' + articleId, (error, response, body) => {
            if (!error && response.statusCode == 200) {
                this.assign('article', JSON.parse(body));
                this.assign('title', '博文管理');
            }
            return this.display();
        });
    }
}